<template>
  <div>
    <van-nav-bar title="修改信息" left-text="返回" left-arrow @click-left="onClickLeft" />
    <!-- 输入任意文本 -->
    <van-field v-model="uname" label="姓名" />
    <!-- 允许输入正整数，调起纯数字键盘 -->
    <van-field v-model="age" type="age" label="年龄" />
    <van-field v-model="gender" type="gender" label="性别" />
    <!-- 输入手机号，调起手机号键盘 -->
    <van-field v-model="phone" type="phone" label="手机号" />
    <!-- 输入密码 -->
    <van-field v-model="password" type="password" label="密码" />
    <van-button round type="info" size="large" @click="onSubmit()" class="vant_btn"
      >提交</van-button
    >
  </div>
</template>

<script>
import { Toast } from "vant";
import url from "../tools/url";
export default {
  name: "Amend",
  data() {
    return {
      uname: "",
      phone: "",
      age: "",
      gender: "",
      password: "",
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSubmit() {
      var token = sessionStorage.getItem("token");
      var str = `id=${this.getInfo.id}&token=${token}&phone=${this.phone}&password=${this.password}&name=${this.uname}&age=${this.age}`;
      this.axios.post(url.GET_USER_ID, str).then((res) => {
        console.log(res);
        if (res.data.code == 200) {
          Toast(res.data.message);
          this.$store.commit("saveInfo", res.data.data);
          this.$router.go(-1);
        } else {
          Toast(res.data.message);
        }
      });
    },
  },
  computed: {
    getInfo() {
      return this.$store.state.info;
    },
  },
};
</script>

<style scoped></style>
